package com.pethome.web.controller;

import com.pethome.common.annotation.Log;
import com.pethome.common.core.controller.BaseController;
import com.pethome.common.core.domain.AjaxResult;
import com.pethome.common.core.page.TableDataInfo;
import com.pethome.common.enums.BusinessType;
import com.pethome.common.utils.poi.ExcelUtil;
import com.pethome.pet.service.IPetService;
import com.pethome.web.domain.Adopt;
import com.pethome.web.service.IAdoptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.sound.midi.Soundbank;
import java.util.List;

/**
 * 领养管理Controller
 * 
 * @author hjc
 * @date 2024-08-26
 */
@Slf4j
@RestController
@RequestMapping("/web/adopt")
public class AdoptController extends BaseController
{
    @Autowired
    private IAdoptService adoptService;
    @Autowired
    private IPetService petService;


    @PostMapping("/adoptPet")
    public Boolean adopt(@RequestBody Adopt adopt){
        log.warn(adopt.toString());
        //初始化申请信息
        log.info("adopt=============>"+adopt.getAdoptPetId());
        //申请信息插入申请领养表
        int res =  adoptService.insertAdopt(adopt);
        return res == 1;
    }

    //同意领养申请
    @GetMapping("/agreeAdopt")
    public AjaxResult agreeAdopt(@RequestParam("adoptId") Long adoptId,@RequestParam("adoptPetId") Long adoptPetId){
        return adoptService.agreeAdopt(adoptId,adoptPetId);
    }

    //反对领养申请
    @GetMapping("/disAgreeAdopt")
    public AjaxResult disAgreeAdopt(@RequestParam("adoptId") Long adoptId){
        return adoptService.disAgreeAdopt(adoptId);
    }
    //添加反馈意见
    @GetMapping("/addText")
    public AjaxResult addText(@RequestParam("adoptId") Long adoptId,@RequestParam("disAgreeText") String disAgreeText){
        return adoptService.addText(adoptId,disAgreeText);
    }

    //获取审核的申请信息和未审核的申请信息
    @GetMapping("/getlist")
    public TableDataInfo getlist(@RequestParam("customerId") Long customerId,@RequestParam("status") Long status){
        System.out.println(customerId);
        System.out.println(status);
        return getDataTable(adoptService.selectByStatus(customerId,status));
    }





    /**
     * 查询领养管理列表
     */
    @PreAuthorize("@ss.hasPermi('web:adopt:list')")
    @GetMapping("/list")
    public TableDataInfo list(Adopt adopt)
    {
        startPage();
        List<Adopt> list = adoptService.selectAdoptList(adopt);
        return getDataTable(list);
    }

    /**
     * 导出领养管理列表
     */
    @PreAuthorize("@ss.hasPermi('web:adopt:export')")
    @Log(title = "领养管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Adopt adopt)
    {
        List<Adopt> list = adoptService.selectAdoptList(adopt);
        ExcelUtil<Adopt> util = new ExcelUtil<Adopt>(Adopt.class);
        util.exportExcel(response, list, "领养管理数据");
    }

    /**
     * 获取领养管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('web:adopt:query')")
    @GetMapping(value = "/{adoptId}")
    public AjaxResult getInfo(@PathVariable("adoptId") Long adoptId)
    {
        return success(adoptService.selectAdoptByAdoptId(adoptId));
    }

    /**
     * 新增领养管理
     */
    @PreAuthorize("@ss.hasPermi('web:adopt:add')")
    @Log(title = "领养管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Adopt adopt)
    {
        return toAjax(adoptService.insertAdopt(adopt));
    }

    /**
     * 修改领养管理
     */
    @PreAuthorize("@ss.hasPermi('web:adopt:edit')")
    @Log(title = "领养管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Adopt adopt)
    {
        return toAjax(adoptService.updateAdopt(adopt));
    }

    /**
     * 删除领养管理
     */
    @PreAuthorize("@ss.hasPermi('web:adopt:remove')")
    @Log(title = "领养管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{adoptIds}")
    public AjaxResult remove(@PathVariable Long[] adoptIds)
    {
        return toAjax(adoptService.deleteAdoptByAdoptIds(adoptIds));
    }





}
